package com.chixing.ih.module.programmer.mapper;

import com.chixing.ih.common.IhRepository;
import com.chixing.ih.module.programmer.mapper.provider.PersonalProjectMapperProvider;
import com.chixing.ih.module.programmer.pojo.PersonalProject;
import com.chixing.ih.module.programmer.pojo.dto.PersonalProjectDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘岩
 * Date: 2020-09-30
 * Time: 8:45
 *
 * @version 1.0
 */
@Mapper
public interface PersonalProjectMapper {

    @UpdateProvider(type = PersonalProjectMapperProvider.class, method = "updateOne")
    int updateOne(PersonalProject personalProject);

    @SelectProvider(type = PersonalProjectMapperProvider.class, method = "listAll")
    @Results(id = "personalProjectMap", value = {
            @Result(id = true, column = "id", property = "personalProject.id"),
            @Result(column = "user_id", property = "personalProject.userId"),
            @Result(column = "project_title", property = "personalProject.projectTitle"),
            @Result(column = "project_desc", property = "personalProject.projectDesc"),
            @Result(column = "project_url", property = "personalProject.projectUrl"),
            @Result(column = "create_time", property = "personalProject.createTime"),
            @Result(column = "update_time", property = "personalProject.updateTime"),

    })
    List<PersonalProjectDTO> listAll(long userId);

    @SelectProvider(type = PersonalProjectMapperProvider.class, method = "listAll")
    @Results(id = "personalProjectsMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "project_title", property = "projectTitle"),
            @Result(column = "project_desc", property = "projectDesc"),
            @Result(column = "project_url", property = "projectUrl"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),

    })
    List<PersonalProject> listPersonalProjects(long userId);


    @InsertProvider(type = PersonalProjectMapperProvider.class, method = "insertOne")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @ResultMap("personalProjectsMap")
    int insertOne(PersonalProject personalProject);

    @DeleteProvider(type = PersonalProjectMapperProvider.class, method = "deleteOneById")
    int deleteOne(long id);

    @SelectProvider(type = PersonalProjectMapperProvider.class, method = "getProjectTitle")
    List<String> getProjectTitle(long userId);


}
